<!DOCTYPE html>
<html lang="zh-CN">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<title>票据打印</title>
		<!--<link rel="stylesheet" href="css/coom.css" />-->
		<link rel="stylesheet" type="text/css" href="css/public.css" />
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			body {
				background: #edecf2;
				width: 100%;
				height: 100%;
				margin: 0;
				padding: 0;
			}
			
			.pri_note .minirefresh-scroll {
				width: 95%;
				margin: 0 auto;
			}
			
			.pri_note ul {
				width: 100%;
margin-top: 0.1rem;
			}
			
			.pri_note ul li {
				/*width: 100%;*/
				background: #fff;
				margin-top: 0.17rem;
				border-radius: 0.2rem ;				
				/*box-shadow: 0 0 10px #999;*/
				padding-bottom: 0.2rem;	
padding-top: 0.1rem;			
			}
			
			.pri_note ul li span {
				display: inline-block;
				width: 1.46rem;
				font: 14px/28px "";
				margin-left: 0.58rem;
				color: #a8a8a8;
				text-align: justify;
			}
			
			.pri_note ul li s {
				
				font: 12px/28px "";
				color: #101010;
				word-wrap: break-word;
			}
			
			.sub {
				display: block;
				width: 4.75rem;
				height: 0.6rem;
				margin: 0 auto;
				background: #38c0a8;
				color: #f8fbff;
				border: none;
				border-radius: 0.45rem;
				font: 0.3rem/0.6rem "";
				margin-top: 0.15rem;
				outline: none;
			}
			
			.kong {
				width: 100%;
				background: #edecf2;
				height: 0.2rem;
			}
			
			input[type=button],
			input[type=submit],
			input[type=file],
			button {
				cursor: pointer;
				-webkit-appearance: none;
			}
			
			.foot {
				height: 0.50rem;
			}
			
			ul {
				/*overflow: auto;*/	
				padding-bottom: 0.8rem;			
			}
		</style>
	</head>

	<body>
		<div class="pri_note" id="app">
			<div id="minirefresh" class="minirefresh-wrap">
				<div class="minirefresh-scroll">
					<ul class="data-list" id="listdata">
						<!--<li >
							<p><span>单据类型：</span><s>{{title}}</s></p>
							<p><span>单据性质：</span> <s>{{title1}}</s></p>
							<p> <span>单据时间：</span><s>{{title2}}</s></p>
							<p> <span>房屋：</span><s>{{title3}}</s> </p>
							<p><span>单据金额：</span><s>{{title4}}</s></p><input type="button" onclick="open_az({{title5}})" class="sub" value="打印" />
						</li>-->
						<!--<div class="kong"></div>-->
					</ul>
					<div class="foot">
						<!--<input type="button" onclick="next()" id="next" class="next sub" value="下一页" />-->
					</div>
					
				</div>
			</div>
		</div>
		<p style="display: none;" id="ppp">1</p>
		<p style="display: none;" id="pppp">1</p>

		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<!--<script type="text/javascript" src="js/min_re.js"></script>-->
		<script src="js/public.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="js/jiazai.js"></script>
		<script>			
			var pagenumber = 1;
			var urlr = getUrl();
			var userid = getUrlParam('userid');
			var areaid = getUrlParam('areaid');
			$(function() {
				var data = JSON.stringify({
					pagenumber: 1,
					pagesize: 5,
					userid: userid,
					areaid: areaid
				});
				ajax_1(data)
			})

			function ajax_1(data) {
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: urlr + "/print/getBillPrintList",
					data: data,
					async: true,
					dataType: "json",
					success: function(msg) {						
						if(msg.code == 200) {							
							var datapp = JSON.parse(msg.returnString);
							var count = msg.count
							$("#ppp").html(msg.count);
							aa(datapp);
							if(count <= pagenumber * 5) {
								$(".next").hide();
								$(".foot").hide();
							}
						} else {
							alert(msg.disp)
						}
					},
					error: function() {
						alert("获取信息失败");
					}
				});
			};

			function aa(datapp) {
				var html_main = '';
				var teldatapp = {};
				for(var i = 0; i < datapp.length; i++) {
					//						console.log(datapp[i].billtype);
					var billid = 'DI' + datapp[i].billid;
					teldatapp[billid] = billid;
					console.log(teldatapp);
					console.log(billid)
					var type = datapp[i].billtype
					if(datapp[i].isprint==1){
						datapp[i].isprint ='已打印'
					} else {
						datapp[i].isprint ='未打印'
					}
					html_main = html_main + '<li>' +
						'<p><span>单据类型：</span><s>' + datapp[i].costname + '</s></p>' +						
						'<p>	<span>单据时间：</span><s>' + datapp[i].billdate + '</s></p>' +
						'<p>	<span>房屋：</span><s>' + datapp[i].areaname + datapp[i].buildname + datapp[i].unitname + datapp[i].rommcode + '</s>	</p>' +
						'<p><span>单据金额：</span><s>' + datapp[i].payamt + '</s></p>' +
						'<p><span>是否打印：</span><s  style="color:red">' + datapp[i].isprint + '</s></p>' +						
						'<input type="button" id="' + billid + '" onclick="open_az(this.id,' + type + ')" class="sub" value="打印" />' +
						'</li>' +
						'<div class="kong"></div>';
				}
				$("#listdata").append(html_main + '<input type="button" onclick="next()" id="next" class="next sub" value="下一页" />');				

			};

			function open_az(id, type, i) {
				console.log(id)				
				console.log(type);
				console.log(arguments[0]);
				billid = arguments[0].substring(2);
				console.log(billid);
				billtype = type;

				//判断操作系统
				var u = navigator.userAgent,
					app = navigator.appVersion;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
				var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				//	           ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端         
				if(isAndroid) {
					//这个是安卓操作系统
					//js调用app方法  getUserDataBayKeys此函数名必须与app方法名一致。	window.Android是调用Android方法。
					window.Android.openScanCode();
				}
				if(isIOS) {　　　　 //这个是ios操作系统
					//			window.webkit.messageHandlers.openScanCode();
//					window.webkit.messageHandlers.openScanCode.postMessage(null);
					window.webkit.messageHandlers.iosCall.postMessage({
						parameter: '', //传递给ios的参数
						callBackResult: "scanCodeResult" //ios方法回调名字
					});
				}

			};
			//app回调过来的函数   函数名必须与app方法名一致。
			function scanCodeResult(data) {
				//				console.log(data);
				//				console.log(JSON.parse(data));
				var dada = JSON.parse(data)
				if(dada.state == 200) {
					var data_pri = {
						printersn: dada.data,
						billid: billid,
						billtype: billtype
					}
					data_pri = JSON.stringify(data_pri);
					ajax_pri_fun(data_pri)
				}
			};

			function ajax_pri_fun(data_pri) {
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: urlr + "/print/printOrder",
					data: data_pri,
					async: true,
					dataType: "json",
					success: function(msg) {
						console.log(msg);
						if(msg.code == 200) {
							alert("打印成功")
						} else {
							alert(msg.disp)
						}
					},
					error: function() {
						alert("获取信息失败");
					}
				});
			};

			function next() {
				pagenumber = pagenumber + 1;
				var data = JSON.stringify({
					pagenumber: pagenumber,
					pagesize: 5,
					userid: userid,
					areaid: areaid
				});
				ajax_1(data)
			}
		</script>
	</body>

</html>